package org.mq.mymq.client.consumer;

import com.alibaba.fastjson.JSON;
import org.mq.mymq.common.coder.TcpMsg;
import org.mq.mymq.common.dto.CreateTopicReqDTO;
import org.mq.mymq.common.enums.BrokerEventCode;
import org.mq.mymq.common.event.EventBus;
import org.mq.mymq.common.remote.BrokerNettyRemoteClient;
import org.mq.mymq.common.remote.BrokerRemoteRespHandler;

import java.util.UUID;

/**
 * @ClassName CreateTopicCommand
 * @Description 创建topic
 * @Author jiarong_ye
 * @Date 2025/7/9 21:11
 * @Version 1.0
 */
public class CreateTopicCommand {
    public static void main(String[] args) {
        String msgId = UUID.randomUUID().toString();
        BrokerNettyRemoteClient brokerNettyRemoteClient = new BrokerNettyRemoteClient("127.0.0.1", 8990);
        brokerNettyRemoteClient.buildConnection(new BrokerRemoteRespHandler(new EventBus("mq-client-eventbus")));
        CreateTopicReqDTO createTopicReqDTO = new CreateTopicReqDTO();
        createTopicReqDTO.setTopic("pay_success");
        createTopicReqDTO.setQueueSize(3);
        createTopicReqDTO.setMsgId(msgId);
        TcpMsg tcpMsg = brokerNettyRemoteClient.sendSyncMsg(new TcpMsg(BrokerEventCode.CREATE_TOPIC.getCode(), JSON.toJSONBytes(createTopicReqDTO)), msgId);
        System.out.println("resp:" + JSON.toJSONString(tcpMsg));
    }
}
